﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// ColorToneEffect Effect
    /// </summary>
    public class ColorToneEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ColorToneEffect), 0);
        public static readonly DependencyProperty DesaturationProperty = DependencyProperty.Register("Desaturation", typeof(double), typeof(ColorToneEffect), new UIPropertyMetadata(0.5, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty TonedProperty = DependencyProperty.Register("Toned", typeof(double), typeof(ColorToneEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty LightColorProperty = DependencyProperty.Register("LightColor", typeof(Color), typeof(ColorToneEffect), new UIPropertyMetadata(Color.FromArgb(255, 255, 229, 128), ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty DarkColorProperty = DependencyProperty.Register("DarkColor", typeof(Color), typeof(ColorToneEffect), new UIPropertyMetadata(Color.FromArgb(255, 51, 128, 0), ShaderEffect.PixelShaderConstantCallback(3)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(ColorToneEffect.InputProperty));
            }
            set
            {
                this.SetValue(ColorToneEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Desaturation du Shader
        /// </summary>
        public double Desaturation
        {
            get
            {
                return ((double)this.GetValue(ColorToneEffect.DesaturationProperty));
            }
            set
            {
                this.SetValue(ColorToneEffect.DesaturationProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Toned du Shader
        /// </summary>
        public double Toned
        {
            get
            {
                return ((double)this.GetValue(ColorToneEffect.TonedProperty));
            }
            set
            {
                this.SetValue(ColorToneEffect.TonedProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété LightColor du Shader
        /// </summary>
        public Color LightColor
        {
            get
            {
                return ((Color)this.GetValue(ColorToneEffect.LightColorProperty));
            }
            set
            {
                this.SetValue(ColorToneEffect.LightColorProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété DarkColor du Shader
        /// </summary>
        public Color DarkColor
        {
            get
            {
                return ((Color)this.GetValue(ColorToneEffect.DarkColorProperty));
            }
            set
            {
                this.SetValue(ColorToneEffect.DarkColorProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static ColorToneEffect()
        {
            ColorToneEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/ColorTone.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public ColorToneEffect()
        {
            this.PixelShader = ColorToneEffect._PixelShader;

            this.UpdateShaderValue(ColorToneEffect.InputProperty);
            this.UpdateShaderValue(ColorToneEffect.DesaturationProperty);
            this.UpdateShaderValue(ColorToneEffect.TonedProperty);
            this.UpdateShaderValue(ColorToneEffect.LightColorProperty);
            this.UpdateShaderValue(ColorToneEffect.DarkColorProperty);
        }

        #endregion
    }
}
